package com.vogue.meeting.common.context;

import com.vogue.meeting.common.security.model.Oauth2User;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

/**
 * User Context
 * */
@Component
public class UserContext {

    /**
     * Authentication 认证对象
     * */
    public Authentication getAuthentication(){
        return SecurityContextHolder.getContext().getAuthentication();
    }

    /**
     * Oauth2User 当前用户
     * */
    public Oauth2User getPrincipal(){
        return (Oauth2User) getAuthentication().getPrincipal();
    }

    /**
     * userName 当前用户名
     * */
    public String getUserName(){ return getPrincipal().getName(); }
    /**
     * 当前用户ID
     * */
    public Integer getId(){ return getPrincipal().getId(); }

}
